package com.zheng.security.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * @author zyq
 * @Description 接口返回统一VO类
 * @createTime 2021年01月10日 15:10:00
 */
@Data
public class ApiResponse implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 表示当前相应的状态是成功或者失败
     */
    private Integer code;
    /**
     * 表示当响应失败之后给前端的错误提示
     */
    private String msg;
    /**
     * 表示当响应成功之后返回给前端的数据
     */
    private Object data;

    public static ApiResponse success(Object data) {
        return new ApiResponse(200, "请求成功", data);
    }

    public static ApiResponse success(String msg, Object data) {
        return new ApiResponse(200, msg, data);
    }

    public static ApiResponse success() {
        return new ApiResponse(200, "请求成功", null);
    }

    public static ApiResponse error(String msg) {
        return new ApiResponse(500, msg, null);
    }

    public static ApiResponse error(Integer code, String msg) {
        return new ApiResponse(code, msg, null);
    }

    public static ApiResponse error(Integer code, String msg, Object object) {
        return new ApiResponse(code, msg, object);
    }

    private ApiResponse(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
